﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using Gao.Poker.Domain;

namespace Gao.Poker.Services
{
    public class BounsService : BaseService
    {
        public List<Bouns> GetBounses(int competitionId)
        {
            return DbContext.Bounses.Where(a => a.CompetitionID == competitionId).ToList();
        }

        public void Save(int competitionID, ObservableCollection<Bouns> bounses)
        {
            foreach (var bouns in bounses)
            {
                bouns.CompetitionID = competitionID;
                if (bouns.ID == 0)
                {
                    if (bouns.Scale <= 0)
                    {
                        continue;
                    }
                    DbContext.Bounses.Add(bouns);
                }
                else
                {
                    var obj = DbContext.Bounses.Find(bouns.ID);
                    DbContext.Entry(obj).CurrentValues.SetValues(bouns);
                }
            }
            DbContext.SaveChanges();
        }
    }
}
